library(tidyverse)
library(magrittr)
outdir <- file.path("..", "output", "timing_master.R")
if(!dir.exists(outdir)) dir.create(outdir)
path <- file.path("..", "output", "timing.R")
mutations.per.year <- seq(1, 10, by=0.01)
fnames <- file.path(path, paste0("timing_",
                                 seq_along(mutations.per.year),
                                 ".rds"))
dat.list <- vector("list", length(fnames))
for(i in seq_along(fnames)){
  if(!file.exists(fnames[i])){
    next()
  }
  dat <- readRDS(fnames[i]) %>%
    gather(mu, value, -Parameter) %>%
    mutate(mutations.per.year=mutations.per.year[i]) %>%
    set_colnames(c("patient", "quantile", "value",
                   "mut.per.yr"))
  dat.list[[i]] <- dat
  cat(".")
}
dat2 <- do.call(rbind, dat.list)
saveRDS(dat2, file=file.path(outdir, "timing.rds"))
unlink(fnames)
